const constants = require("../../data/constants");
const adminModel = require('../../model/admin');
var UUID = require('uuid');

let admin={};
/**
  登陆
 * @param {*} req 
 * @param {*} res 
 */
admin.checklogin=async(req,res)=>{
    
    let username = req.body.username;
    let password = req.body.password;
    if(!username || !password){
        res.send(constants.httpCode.ILLEGAL_PARAM);
    }else{
        await adminModel.checklogin(username,password).then((data)=>{
            console.log('then then',data);
            let token = UUID.v1().replace(/-/g,'');
            res.send( Object.assign(constants.httpCode.OK , {data:{token:token}}));
            
        }).catch((err)=>{
            console.error(err)
            res.send(constants.httpCode.ILLEGAL_PARAM);
        });
    }
}

// 注销
admin.logout=function(req,res){
    res.send(Object.assign(constants.httpCode.OK,{data:{}}));
}

// 用户信息
admin.info=function(req,res){
    res.send(Object.assign(constants.httpCode.OK,{data:{token:''}}));
}

module.exports=admin;